package com.goldgov.utils;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSONObject;
import com.goldgov.kcloud.core.json.JsonErrorObject;
import com.goldgov.kcloud.core.json.JsonObject;
import com.goldgov.kcloud.core.json.JsonSuccessObject;

public class PrintUtil {
	
    public static void print(HttpServletResponse response,boolean b) {  
    	response.setContentType("application/json");
    	response.setCharacterEncoding("utf-8");
		try {
			PrintWriter pw=response.getWriter();
			if(b) {
				pw.write(JSONObject.toJSONString(JsonSuccessObject.SUCCESS));
			}else {
				pw.write(JSONObject.toJSONString(JsonErrorObject.ERROR));
			}
			pw.flush();
			pw.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
    	  
    }  
	
    public static void printMsg(HttpServletResponse response,boolean b,String msg) {  
    	response.setContentType("application/json");
    	response.setCharacterEncoding("utf-8");
    	try {
    		PrintWriter pw=response.getWriter();
    		if(b) {
    			pw.write(JSONObject.toJSONString(new JsonSuccessObject<String>("", "2000", msg)));
    		}else {
    			pw.write(JSONObject.toJSONString(new JsonErrorObject<String>("", msg)));
    		}
    		pw.flush();
    		pw.close();
    	} catch (IOException e) {
    		e.printStackTrace();
    	}
    	
    }  
    
}
